package pro.survey.analyzer.lectors.window;

import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.control.CheckBox;

/**
 *
 * @author Adrian
 */
public class LectorCheckBox extends CheckBox {
    
    private int lectorId;

    public int getLectorId() {
        return lectorId;
    }
    
    public LectorCheckBox(String title, int lectorId) {
        super(title);
        this.lectorId = lectorId;
        this.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent t) {
                if (isSelected())
                    LectorsWindow.getInstance().getButtonOK().setDisable(false);
                else {
                    int countSelectedCheckBox = 0;
                    for (LectorCheckBox cb : LectorsWindow.getInstance().getCbs()) {
                        if (cb.isSelected())
                            countSelectedCheckBox++;
                    }
                    
                    if (countSelectedCheckBox > 0) {
                        LectorsWindow.getInstance().getButtonOK().setDisable(false);
                    } else {
                        LectorsWindow.getInstance().getButtonOK().setDisable(true);
                    }
                }
            }
        });
    }
}
